﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;
using System.Xml;

namespace WebRaoVat.Admin
{
    public partial class QuanLyGiaoDien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LaAdmin"] == null || Session["LaAdmin"].ToString().Length <= 0)
            {                
                //Response.Redirect("../Default.aspx");
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //LogoDTO logo = new LogoDTO();
            //if (LogoBUS.getAll().Count > 0)
            //    logo = LogoBUS.getAll()[0];
            //else
            //    logo.DuongDanLogo = "images/logo.gif";
            

            //XmlDocument taiLieu = null;
            //try
            //{
            //    taiLieu = XL_XML.ReadDocumentFile(Server.MapPath("../Gui.xml"));
            //}
            //catch { }
            //if (taiLieu == null)
            //    return;

            //XL_XML.DeleteNode(taiLieu, "//GIAODIEN/LOGO");// xóa MENU cũ ra
            //ThemLogo(taiLieu, logo);

            //XL_XML.WriteDocument(taiLieu, Server.MapPath("../Gui.xml"));
        }

        public void ThemLogo(XmlDocument taiLieu, LogoDTO logo)
        {
            //List<string> tenThuocTinh = new List<string>();
            //List<string> giaTriThuocTinh = new List<string>();
            //tenThuocTinh.Add("duongdan"); giaTriThuocTinh.Add(logo.DuongDanLogo);
            //XmlNode Menu = XL_XML.CreateNode(taiLieu, "LOGO", tenThuocTinh, giaTriThuocTinh);
            //XL_XML.AddNode(taiLieu, "//GIAODIEN", Menu);
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            //Thay đổi slogant
            /*lbThongBao.Text = "";

            XmlDocument taiLieu = null;
            try
            {
                taiLieu = XL_XML.ReadDocumentFile(Server.MapPath("../Gui.xml"));
            }
            catch { }
            if (taiLieu == null)
                return;

            XL_XML.DeleteNode(taiLieu, "//GIAODIEN/SLOGANT");// xóa SLOGANT cũ ra

            List<string> tenThuocTinh = new List<string>();
            List<string> giaTriThuocTinh = new List<string>();
            tenThuocTinh.Add("one"); giaTriThuocTinh.Add(txtSlogan1.Text);
            tenThuocTinh.Add("true"); giaTriThuocTinh.Add(txtSlogan2.Text);
            XmlNode Slogant = XL_XML.CreateNode(taiLieu, "SLOGANT", tenThuocTinh, giaTriThuocTinh);

            if (XL_XML.AddNode(taiLieu, "//GIAODIEN", Slogant))
            {
                XL_XML.WriteDocument(taiLieu, Server.MapPath("../Gui.xml"));

                lbThongBao.Text = "Thành công!";
            }*/
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            string filepath = "";
            if ("" != FileAnhNen.PostedFile.FileName)
            {
                string duongDan = Server.MapPath("~/images");
                string tenthat = Guid.NewGuid().ToString() + "." + FileAnhNen.PostedFile.FileName.Split('.')[1];
                duongDan += "/" + tenthat;
                FileAnhNen.PostedFile.SaveAs(duongDan);

                int _count = duongDan.LastIndexOf("\\");
                filepath = duongDan.Remove(0, _count + 1);
            }
            else
                return;

            tbThongBaoThayDoiNen.Text = "";

            XmlDocument taiLieu = null;
            try
            {
                taiLieu = XL_XML.ReadDocumentFile(Server.MapPath("../Gui.xml"));
            }
            catch { }
            if (taiLieu == null)
                return;

            XL_XML.DeleteNode(taiLieu, "//GIAODIEN/ANH_NEN");// xóa SLOGANT cũ ra

            List<string> tenThuocTinh = new List<string>();
            List<string> giaTriThuocTinh = new List<string>();
            tenThuocTinh.Add("duongdan"); giaTriThuocTinh.Add(filepath);
            
            XmlNode Slogant = XL_XML.CreateNode(taiLieu, "ANH_NEN", tenThuocTinh, giaTriThuocTinh);

            if (XL_XML.AddNode(taiLieu, "//GIAODIEN", Slogant))
            {
                XL_XML.WriteDocument(taiLieu, Server.MapPath("../Gui.xml"));

                tbThongBaoThayDoiNen.Text = "Thành công!";
            }
        }

    }
}
